Population#
In this Notebook, we will be looking at the population and it’s distribution in Freiberg. The Data is from the 2011 Census.
cfg = ConfigObj(r"..\notebook.ini")
csv10m = Path((Path(".").parent), "csvs", "Freiberg, Sachsen-10m.csv")
df = pd.read_csv(csv10m)
df.columns = ["id", "lon", "lat", "pop"]
df = df.set_index("id")
df
| lon | lat | pop | |
|---|---|---|---|
| id | |||
| 0 | 13.327293 | 50.875905 | 0.80 |
| 1 | 13.327435 | 50.875905 | 0.80 |
| 2 | 13.327577 | 50.875905 | 0.80 |
| 3 | 13.327719 | 50.875905 | 0.80 |
| 4 | 13.327862 | 50.875905 | 0.80 |
| ... | ... | ... | ... |
| 107095 | 13.330049 | 50.944991 | 0.03 |
| 107096 | 13.330191 | 50.944991 | 0.03 |
| 107097 | 13.330333 | 50.944991 | 0.03 |
| 107098 | 13.330475 | 50.944991 | 0.03 |
| 107099 | 13.330617 | 50.944991 | 0.03 |
107100 rows × 3 columns
fig, ax = plt.subplots(figsize=(16, 12))
ax = df.plot.hexbin(x="lon",
y="lat",
C="pop",
reduce_C_function=np.sum,
gridsize=50,
ax=ax)
tags = {"type": "boundary"}
place = "Freiberg, Sachsen"
# gdf = ox.geometries_from_place(, tags)
# gdf.plot()
bbox = ox.geocoder.geocode_to_gdf(place, buffer_dist=200)
geom = bbox.geometry.loc[0]
p = gpd.GeoSeries(geom).geometry.boundary
ax = p.plot(color=None, edgecolor='k', linewidth=2, ax=ax)
figure = ax.get_figure()
figure
<Figure size 640x480 with 0 Axes>
def heat_map(df):
# lat/long/weight
try:
data = df[["lat", "lon", "pop"]]
except KeyError:
data = df[["x", "y", "einwohner"]]
# print(df["2"].max())
m = folium.Map([50.9, 13.37], zoom_start=12)
HeatMap(data, min_opacity=0.4,
gradient={.4: 'blue', .8: 'lime',
0.9: 'yellow', 0.95: 'orange', 1: 'red'}
).add_to(folium.FeatureGroup(name='Heat Map').add_to(m))
folium.LayerControl().add_to(m)
# m.save('{0}.html'.format('Freiberg-census-10m'))
return m
heat_map(df)
Make this Notebook Trusted to load map: File -> Trust Notebook
cfg = ConfigObj("notebook.ini")
scenarios = cfr.get_scenarios(cfg)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Small")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Small")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Medium")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Medium-restricted")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Large")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)
G = oh.get_place(placename=place, simplify=True,
clean_periphery=True,
file_identifier="", retain_all=True)
G_nx = r4r.load_pop_scenario(cfg, G, place, "Optimal")
to_remove = []
for node in G_nx.nodes():
try:
G_nx.nodes[node]["pop"]
except KeyError:
to_remove.append(node)
G.remove_nodes_from(to_remove)
x = ox.plot_graph(G,
figsize=(16, 12),
node_color=ox.plot.get_node_colors_by_attr(G, "pop"),
node_size=5,
edge_linewidth=0.1)
x
(<Figure size 1600x1200 with 1 Axes>, <Axes: >)